package dao

import (
	"system_go/models"
)

func GetAllPets(petsParam map[string]interface{}) (error, []models.Pet, int64) {
	var petsData []models.Pet
	page := petsParam["page"].(int)
	pageSize := petsParam["limit"].(int)
	searchName := petsParam["searchName"].(string)
	var total int64
	err := db.Table("pet").Where("petname like ? ", "%"+searchName+"%").Order("petid ASC").Count(&total).Offset((page - 1) * pageSize).Limit(pageSize).Find(&petsData).Error
	return err, petsData, total
}

func AddPets(pets models.Pet) error {
	err := db.Table("pet").Select("petid", "petname", "petvar", "petage", "petmemid", "petremark").Create(&pets).Error
	return err
}

func DelPets(id string) error {
	err := db.Table("pet").Where("petid = ?", id).Delete(models.Pet{}).Error
	return err
}

func UpdatePets(pets models.Pet) error {
	err := db.Table("pet").Where("petid = ?", pets.Petid).Updates(&pets).Error
	return err
}
